<?php
$con = mysql_connect("localhost","cubeMass_f","cubeSelectNow");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("cubeMass", $con);

include("dataClass.php");







if($_POST["state"]=="normal"){
	$modelList = $_POST['modelList'];
	//$modelList = strtr($modelList,"_",",");
	$modelArray = explode("_",$modelList,4);
	$modelArray = array_reverse($modelArray);
	$modelList = implode(",",$modelArray);
	
	$modelSql = "SELECT * FROM model WHERE ID IN (".$modelList.")ORDER BY find_in_set(ID,'".$modelList."')";
	$result =  mysql_query($modelSql);
	$listNumber=@mysql_num_rows($result);
	if($listNumber!=0){
	echo "<div class='contentList_name'>|浏览历史|</div><div class='content_line'></div><div class='contentList_container'>";
	while($row = mysql_fetch_array($result)){
			echo "<div class='contentListBlock'>";
			echo "<a href='http://www.eizia.com/cube/".$row['ID'].".html'><span class='imgSpan_150x100'>";
				echo "<img class='modelImg_150x100' src='http://www.eizia.com/photo/".$row['ID']."_small.png' alt='".$row['description']."' title=".$row['description']." /></span>";
				echo "<span class='nameSpan_150x100' title='".$row['name']."'>".$row['name']."</span>";
				echo "<span class='viewTimesSpan_150x100'>人气:".$row['visitedTimes']."</span>";
				$userResult = mysql_query("SELECT * FROM user WHERE ID = '$row[USER_ID]'");
				$userRow = mysql_fetch_array($userResult);
				echo "<span class='usernameSpan_150x100'>用户:".$userRow['name']."</span>";
			echo "</a>";
			echo "</div>";
		}
	echo "</div>";
		}
	}
elseif($_POST["state"]=="userList" && $_POST["model_id"]){
		$model_id = $_POST["model_id"];
		$modelSql = "SELECT * FROM user WHERE ID = (SELECT USER_ID FROM model WHERE ID = '$model_id')";
		$result =  mysql_query($modelSql);
		$userRow = mysql_fetch_array($result);
		$modelSql = "SELECT * FROM model WHERE USER_ID = (SELECT USER_ID FROM model WHERE ID = '$model_id') AND state = '0' ORDER BY lastEditTime desc";
		$result =  mysql_query($modelSql);
		$listNumber=@mysql_num_rows($result);
			echo "<div class='tabs_name'>|该用户的作品|".$listNumber."</div><div class='userTabs_line'></div>";
			echo "<div class='tabs_container'><ul>";
		while($modelRow = mysql_fetch_array($result)){
			echo "<li class='modelListBlock'>";
			echo "<a href='http://www.eizia.com/cube/".$modelRow['ID'].".html'><span class='imgSpan_120x80'>";
				echo "<img class='modelImg_120x80' src='http://www.eizia.com/photo/".$modelRow['ID']."_small.png' alt='".$modelRow['description']."' title=".$modelRow['description']." /></span>";
				echo "<span class='nameSpan_120x80'  title='".$modelRow['name']."'>".$modelRow['name']."</span>";
				echo "<span class='viewTimesSpan_120x80'>人气:".$modelRow['visitedTimes']."</span>";
				echo "<span class='userNameSpan_120x80'>用户:".$userRow['name']."</span>";
			echo "</a>";
			echo "</li>";
			}
			echo "</ul></div>";
	}
elseif($_POST["state"]=="latestModels"){
	$modelSql = "SELECT * FROM model ORDER BY ID desc LIMIT 8";
	$result = mysql_query($modelSql);
	echo "<div class='contentList_name'>|最近更新|</div><div class='content_line'></div><div class='contentList_container'>";
	while($row = mysql_fetch_array($result)){
			echo "<div class='contentListBlock'>";
			echo "<a href='http://www.eizia.com/cube/".$row['ID'].".html'><span class='imgSpan_150x100'>";
				echo "<img class='modelImg_150x100' src='http://www.eizia.com/photo/".$row['ID']."_small.png' alt='".$row['description']."' title=".$row['description']." /></span>";
				echo "<span class='nameSpan_150x100' title='".$row['name']."'>".$row['name']."</span>";
				echo "<span class='viewTimesSpan_150x100'>人气:".$row['visitedTimes']."</span>";
				$userResult = mysql_query("SELECT * FROM user WHERE ID = '$row[USER_ID]'");
				$userRow = mysql_fetch_array($userResult);
				echo "<span class='usernameSpan_150x100'>用户:".$userRow['name']."</span>";
			echo "</a>";
			echo "</div>";
		}
	echo "</div>";
	}
elseif($_POST["state"]=="relatedModels"){
	$model_id = $_POST["model_id"];
	//$articleid = 10173;
	
	$query = $db->query("SELECT * FROM model WHERE ID = $model_id");
	$modelRow = $db->getarray($query);
	$model_name = str_replace("我的"," ",$modelRow['name']);
	$words = ChineseWordSegment($model_name);
	//print($words);
	$sqlstr = '(';
	foreach($words as $k=>$w){
	$im = 1 + showtimes($w,strip_tags($modelRow['name']));
	$sqlstr .= ($k?'+':'')."(`name` like '%".mysql_escape_string($w)."%')*$im";
	}
	$sqlstr .= ")";
	$mysql = "select *,$sqlstr as related from model where ID<>$model_id and $sqlstr order by related desc,rand() limit 7";
	$query = $db->query($mysql);
	$listNumber=@mysql_num_rows($query);
	if($listNumber!=0){
		echo "<div class='tabs_name'>|相似的作品|</div><div class='userTabs_line'></div>";
		echo "<div class='tabs_container'><ul>";
	while($row = $db->getarray($query)){
		echo "<li class='modelListBlock'>";
		echo "<a href='http://www.eizia.com/cube/".$row['ID'].".html'><span class='imgSpan_120x80'>";
			echo "<img class='modelImg_120x80' src='http://www.eizia.com/photo/".$row['ID']."_small.png' alt='".$row['description']."' title=".$row['description']." /></span>";
			echo "<span class='nameSpan_120x80'  title='".$row['name']."'>".$row['name']."</span>";
			echo "<span class='viewTimesSpan_120x80'>人气:".$row['visitedTimes']."</span>";
				$userResult = mysql_query("SELECT * FROM user WHERE ID = '$row[USER_ID]'");
				$userRow = mysql_fetch_array($userResult);
			echo "<span class='userNameSpan_120x80'>用户:".$userRow['name']."</span>";
		echo "</a>";
		echo "</li>";
		}
		echo "</ul></div>";
	}
	else{
		echo "<div class='tabs_name'>|相似的作品|-_-！一个都没有找到</div><div class='userTabs_line'></div>";
		echo "<div class='tabs_container'><ul>";
		}
	}
//----------------------------------------------------------------------------------------
function ChineseWordSegment($str){
	$words = array();
	$pa = "/[[:punct:]|\\s_]+|[a-z0-9]+|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]/mi";
	$punctcn = "～！·＃￥％…—＊（）—＋｛｝［］｜、；：‘’“”，。《》？／　";
	preg_match_all($pa,$str,$r);
	$lv = '';
	foreach($r[0] as $k=>$v) {
	if(ord($v[0])<128){
	if(preg_match('/^[a-z0-9]{2,}$/i',$v)) $words[] = $v;
	$lv = '';
	continue;
	}
	if(strrchr($punctcn,$v)){
	$lv = '';
	continue;
	}
	if($lv) $words[] = $lv.$v;
	$lv = $v;
	}
	return $words;
}
function showtimes($word,$content){
	$nc = str_replace("$word","",$content);
	return (strlen($content)-strlen($nc))/strlen($word);
}


/*	
echo "<div class='tabs_name'>|最近浏览的作品|</div><div class='userTabs_line'></div>";
echo "<div class='tabs_container'><ul>";
while($row = mysql_fetch_array($result)){
echo "<li class='modelListBlock'>";
echo "<a href='http://www.eizia.com/cube/".$row['ID'].".html'><span class='imgSpan_120x80'>";
	echo "<img class='modelImg_120x80' src='http://www.eizia.com/".$row['picSrc']."'/></span>";
	echo "<span class='nameSpan_120x80'>".$row['name']."</span>";
	echo "<span class='viewTimesSpan_120x80'>观看次数：".$row['visitedTimes']."</span>";
	echo "<span class='userNameSpan_120x80'>所有者：".$row['USER_ID']."</span>";
echo "</a>";
echo "</li>";
}
echo "</ul></div>";
*/



















































mysql_close($con);
?>
